{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Project: Finite Difference Methods\n",
    "\n",
    "The purpose of this project is to implement the finite difference method (5-point stencil) for\n",
    "solving the Poisson equation in a rectangular domain using matrix-free or tensor product matrix. \n",
    "\n",
    "Reference: \n",
    "\n",
    "* [Finite Difference Methods](http://math.uci.edu/~chenlong/226/FDM.pdf)\n",
    "* [Programming of Finite Difference Methods](http://math.uci.edu/~chenlong/226/FDMcode.pdf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 1: Uniform Grids and Grid Functions\n",
    "\n",
    "Use `meshgrid` or `ndgrid` to generate a uniform grid of the rectangle $(0,1)\\times (0,2)$ with size `h`.\n",
    "\n",
    "Evaluate a function `f(x,y)` on this uniform grid. Plot it using `mesh` or `surf`."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 2: Matrix-Vector Product\n",
    "\n",
    "Compare the following three ways of computing `A*u`\n",
    "\n",
    "* Generate a big sparse matrix using the tensor product of 1-D tri-diagonal finite difference matrix and compute `A*u` using this matrix\n",
    "\n",
    "* Code matrix-free version of `A*u`\n",
    "\n",
    "* Use the 1-D matrix and tensor product structure to compute `A*u`\n",
    "\n",
    "Use them to verify the truncation error. That is, choosing the exact\n",
    "solution `u` and compute the max norm of `A*u - f`. Change `h` and show the\n",
    "order of the truncation error."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 3: Boundary Conditions\n",
    "\n",
    "**Dirichlet boundary condition.** Evaluate the boundary condition at\n",
    "boundary vertices and move to the right hand side.\n",
    "\n",
    "**Neumann boundary condition.** Change the stencil near the boundary and\n",
    "modify the right hand side."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 4: Solve the Linear Algebraic Systems\n",
    "\n",
    "* Direct methods: Use the big matrix to solve `u = A\\f`.\n",
    "\n",
    "* Iterative methods: Implement Gauss-Seidel method as a subroutine `GS(u,f)` and iterate\n",
    "\n",
    "      while err > tol\n",
    "           u = GS(u,f);\n",
    "           err = norm(f-A*u)/norm(f);\n",
    "      end"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 5: Convergence\n",
    "\n",
    "* Choose a smooth solution `u` and calculate the right hand side `f` and boundary conditions for the unit square.\n",
    "\n",
    "* Compute the error `uI - uh` in the maximum norm, where `uI` is the nodal interpolation of `u`.\n",
    "\n",
    "* Change the mesh size `h` from `1/8,1/16,1/32,1/64` and show the order of the error."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Matlab",
   "language": "matlab",
   "name": "matlab"
  },
  "language_info": {
   "codemirror_mode": "octave",
   "file_extension": ".m",
   "help_links": [
    {
     "text": "MetaKernel Magics",
     "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
    }
   ],
   "mimetype": "text/x-matlab",
   "name": "matlab",
   "version": "0.14.3"
  },
  "toc": {
   "colors": {
    "hover_highlight": "#DAA520",
    "navigate_num": "#000000",
    "navigate_text": "#333333",
    "running_highlight": "#FF0000",
    "selected_highlight": "#FFD700",
    "sidebar_border": "#EEEEEE",
    "wrapper_background": "#FFFFFF"
   },
   "moveMenuLeft": true,
   "nav_menu": {
    "height": "120px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": false,
   "widenNotebook": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
